{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5ea5f7d2",
   "metadata": {},
   "source": [
    "# 尝试完成项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c0554a3d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "   WARNING: This is a development server. Do not use it in a production deployment.\n",
      "   Use a production WSGI server instead.\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:15] \"\u001b[37mGET / HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:16] \"\u001b[33mGET /docs/5.1/dist/js/bootstrap.bundle.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:16] \"\u001b[33mGET /docs/5.1/assets/img/favicons/manifest.json HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:22] \"\u001b[33mGET /docs/5.1/assets/img/favicons/manifest.json HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:27] \"\u001b[33mGET /docs/5.1/assets/img/favicons/manifest.json HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:32] \"\u001b[33mGET /docs/5.1/assets/img/favicons/manifest.json HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:35] \"\u001b[37mGET /index HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:35] \"\u001b[33mGET /docs/5.1/dist/js/bootstrap.bundle.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:36] \"\u001b[33mGET /docs/5.1/assets/img/favicons/manifest.json HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:45] \"\u001b[33mGET /docs/5.1/getting-started/introduction/ HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:47] \"\u001b[33mGET /docs/5.1/assets/img/favicons/manifest.json HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:13:51] \"\u001b[33mGET /docs/5.1/assets/img/favicons/manifest.json HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:14:06] \"\u001b[33mGET /docs/5.1/assets/img/favicons/manifest.json HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:14:09] \"\u001b[37mGET /index HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:14:09] \"\u001b[33mGET /docs/5.1/dist/js/bootstrap.bundle.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:14:10] \"\u001b[33mGET /docs/5.1/assets/img/favicons/manifest.json HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:14:15] \"\u001b[33mGET /docs/5.1/assets/img/favicons/manifest.json HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:14:17] \"\u001b[33mGET /index_vowels HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [27/Dec/2021 19:14:19] \"\u001b[33mGET /docs/5.1/assets/img/favicons/manifest.json HTTP/1.1\u001b[0m\" 404 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask\n",
    "from flask import render_template\n",
    "\n",
    "# flask角色：中央登记中心\n",
    "# 1.路由route\n",
    "# 1.1 url 相对路径：不完整的路径（相对于IP地址的路径，所以IP地址和端口号不需要写）\n",
    "# 绝对路径是完整路径。\n",
    "# 1.2 request 的请求方法：【GET默认】【POST】\n",
    "# 2 视图函数\n",
    "\n",
    "app = Flask(__name__)\n",
    "#  【GET默认】\n",
    "@app.route(\"/\")\n",
    "def hello_world():\n",
    "    return  render_template('hello.html')\n",
    "\n",
    "\n",
    "# 【GET默认】\n",
    "@app.route(\"/index\")\n",
    "def index():\n",
    "    return render_template('index.html')\n",
    "\n",
    "# 【POST】:用户提交的数据用POST方法\n",
    "@app.route(\"/result\",methods=['POST'])\n",
    "def result():\n",
    "    # 我们怎么接受数据？ flask提供了request.form的方法用来\n",
    "    # 接受用户数据\n",
    "    # 第一个项目 ：名字的全称\n",
    "    py_firstname = request.form['firstname']\n",
    "    py_lastname = request.form['lastname']\n",
    "    py_fulltname = py_firetname.title() + '' + py_lastname.title()\n",
    "    return render_template('result.html',\n",
    "                          fullname = py_fullname\n",
    "                          )\n",
    "\n",
    "# 第二个项目：元音字母表词频统计\n",
    "    py_word = request.form['word']\n",
    "    py_vowels = request.form['vowels']\n",
    "    py_found = {}\n",
    "    for i in py_word:\n",
    "        if i in py_vowels:\n",
    "            py_found.setefault(i,0)\n",
    "            py_found[i]+=1\n",
    "            \n",
    "\n",
    "    return render_template('result.html',\n",
    "                          fullname = py_fullname)\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2db1ce6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
